
{template header}

<script type="text/javascript" src="{SITE_URL}public/js/jquery.upload.v2.js"></script>

<div class="container">


<div class="row">


<div class="col-md-8">


    <div class="panel panel-default">
        <div class="panel-body">

 <div class="duty_list" id="dutyshow">


		<div class="userimg"><a href="{tsUrl('user','duty',array('id'=>$strDuty[user][userid],'groupid'=>$strArticle[groupid]))}"><img class="img-rounded" src="{$strDuty[user][face]}" width="32" height="32" alt="{$strDuty['user']['username']}" title="{$strDuty['user']['username']}" /></a></div>

		<div class="duty_title">
			<div class="title">

				<div class="author"><a href="{tsUrl('user','duty',array('id'=>$strDuty[user][userid],'groupid'=>$strArticle[groupid]))}">{$strDuty[user][username]}</a><span style="float: right;color: #c0c0c0">{$strDuty[count_recommend]} 赞</span></div>
				<div class="content"  style="font-size:14px;line-height:30px;overflow: hidden;word-wrap: break-word;word-break: normal;color:{if $strDuty['status']<1}#c0c0c0{else}#000000{/if}" >
					{if $strDuty['endtime']==0}{php echo date('Y-m-d',$strDuty['begintime'])}{else}{php echo date('Y-m-d H:i',$strDuty['begintime'])}至{php echo date('H:i',$strDuty['endtime'])}{/if}在{if ($GLOBALS[TS_USER][userid]==$strDuty['userid']||$GLOBALS['TS_USER']['isadmin']=='1')&&$strDuty['status']==0}<a onclick="setgroup({$strDuty[dutyid]})">{/if}{php echo $strDuty['group']['groupname']}执行{$strDuty['cate']}，{if ($GLOBALS[TS_USER][userid]==$strDuty['userid']||$GLOBALS['TS_USER']['isadmin']=='1')&&$strDuty['status']==0}</a>{/if}{if $strDuty['commute']==0}服务{php echo $strDuty['period']}小时{else}实际服务{$strDuty['period']}小时，通勤时间{php echo $strDuty['commute']}小时，合计耗时{php echo $strDuty['term']}小时{/if}。{if $strDuty['job']}<br/>{php echo delempty($strDuty['job'])}{/if}
				</div>
				{if $strDuty['image']}

				<div class="piclist">
					<ul>
						{loop $strDuty['image'] $k $pic}
						<li style="border-bottom: none"><a href="{$pic}"><img style="width:100px;height: auto;position:absolute; clip:rect(0px 120px 70px 0px); " src="{$pic}"></a></li>

						{/loop}
					</ul>
				</div>
				{/if}
				{if $strDuty['comment']}

					<ul style="background-color: #f7f7f7;border-radius: 5%;margin-top: 20px">
						{loop $strDuty['comment'] $k $v}
							<li style="border-bottom: 0px;">
								<div class="userimg"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}"><img class="img-rounded" src="{$v[user][face]}" width="32" height="32" alt="{$v['user']['username']}" title="{$v['user']['username']}" /></a></div>
								<div class="duty_title">
									<div class="title">
										<div class="author"><a href="{tsUrl('user','duty',array('id'=>$v[user][userid]))}">{$v[user][username]}</a>&nbsp;&nbsp;{php echo getTime($v[addtime],time())}</div>
										<div class="content">{$v[content]}</div>
										{if $GLOBALS[TS_USER][userid] == $item[userid] || $GLOBALS[TS_USER]['isadmin']==1}
										<span><a style="float:right" href="{SITE_URL}index.php?app=duty&ac=delcomment&commentid={$v['commentid']}"  rel="nofollow">删除</a> </span>
										{/if}
									</div>
								</div>

							</li>

						{/loop}
					</ul>

				{/if}
<div style="text-align:right;font-size: x-small;color: #777777">


	{if $GLOBALS[TS_USER][userid]==$strDuty['userid']&&$strDuty['status']==1}

	<a class="btn btn-w" style="background-color: #419641;color: #FFFFFF" href="{tsUrl('duty','card',array('dutyid'=>$strDuty[dutyid]))}">打卡</a>

	{/if}

	{if $strDuty['articleid']>0}
	<a class="btn btn-w" href="{tsUrl('article','show',array('id'=>$strDuty[articleid]))}{$mylink}">读文档</a>
	{/if}


	{if $GLOBALS[TS_USER][userid]==$strDuty['userid']}

	{/if}
	{if $GLOBALS['TS_USER']['isadmin']=='1'||$GLOBALS[TS_USER][userid]==$strDuty['userid']&&$strDuty['status']==0}<a  class="btn btn-w" href="javascript:void('0');" onclick="openEditor()">修改</a>{/if}
	{if ($GLOBALS[TS_USER][userid]==$strDuty['userid']||$GLOBALS['TS_USER']['isadmin']=='1')&&$strDuty['status']<1}<a  class="btn btn-w" href="javascript:void('0');" onclick="delDuty('{$strDuty['dutyid']}')">删除</a>{/if}

	{if (in_array($GLOBALS[TS_USER][userid],$strDuty['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$strDuty['status']==0}<a  class="btn btn-w" href="javascript:void('0');" onclick="verify('{$strDuty['dutyid']}')">核定</a>{/if}
	{if (in_array($GLOBALS[TS_USER][userid],$strDuty['group']['admin'])||$GLOBALS['TS_USER']['isadmin']=='1')&&$strDuty['status']==1}<a class="btn btn-w" href="javascript:void('0');" onclick="cancel('{$strDuty['dutyid']}')">取消核定</a>{/if}
	{if $GLOBALS[TS_USER][userid]&&$strDuty['status']==1&&$strDuty[userid]!=$GLOBALS[TS_USER][userid]}
	<a class="btn btn-w" href="javascript:void('0');" onclick="recommend({$strDuty['dutyid']})">{if $isRecommend==0} 点赞{else} 取消点赞{/if}</a>
	{/if}
  {if $GLOBALS[TS_USER][userid]>0}
	<a class="btn btn-w" href="javascript:void(0)" onclick="add_comment('{$strDuty[dutyid]}')">评论</a>
	{/if}


</div>
</div>
</div>



<div class="clear"></div>


</div>

			<div id="do_duty_form" style="display: none" >
				<br/>
				<form  id="record" class="form-horizontal" method="post" action="{SITE_URL}index.php?app=user&ac=do&ts=add">
					<input type="hidden" id="dutyid" name="dutyid" value="{$strDuty['dutyid']}">
					{if $GLOBALS['TS_USER']['isadmin']=='1'&&$strDuty['userid']!=$GLOBALS['TS_USER']['userid']}
					{/if}
					<div class="form-group">
						<label class="col-sm-3 control-label">身份证号（或护照号等）</label>
						<div class="col-sm-9">
							<input type="text" class="form-control" id="idcard" name="idcard" value="{$arrUser['idcard']}" placeholder="请输入身份证号（或护照号等），否则服务时长无法按月导入官方志愿平台">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">姓名</label>
						<div class="col-sm-9">
							<input type="text" class="form-control" id="username" name="username" value="{$arrUser['username']}">
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">服务类型</label>
						<div class="col-sm-9">
							<select  name="cateid" id="cateid" class="form-control">
								<option value=""></option>
								{loop $arrCate $key $item}

								<option value="{$item['cateid']}" {if $strDuty['cateid']==$item['cateid']}selected{/if} >{$item['catename']}</option>

								{/loop}
							</select>
						</div>
					</div>

						<div class="form-group">
						<label class="col-sm-3 control-label">服务处所</label>
						<div class="col-sm-9">
							<select  name="groupid" id="gid" class="form-control">
								<option value=""></option>
								{loop $strGroup $key $item}

								<option value="{$item['groupid']}" {if $item['groupid']==$strDuty['groupid']}selected{/if}>{$item['groupname']}</option>

								{/loop}
							</select>
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">服务起始时间</label>
						<div class="col-sm-3">
							<input class="form-control"  name="begindate" readonly value="{php echo date('Y-m-d H:i',$strDuty[begintime])}" id="begintime" />
						</div>

					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">服务结束时间</label>
						<div class="col-sm-3">
							<input class="form-control" name="enddate" readonly value="{php echo date('Y-m-d H:i',$strDuty[endtime])}" id="endtime" />
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">实际耗时（小时）</label>
						<div class="col-sm-9">
							<input type="text" class="form-control" name="period" id="period" value="{$strDuty[preiod]}" placeholder="可留空，根据起止时间自动计算">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-3 control-label">通勤时长（小时）</label>
						<div class="col-sm-9">
							<input type="text" class="form-control" name="commute" id="commute"  value="{$strDuty[commute]}">
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-3 control-label">工作小结及注意事项</label>
						<div class="col-sm-9" >
							<div id="tseditor">{$strDuty['content']}</div>
							<div style="display: none">
								<textarea name="content" class="form-control" style="width: 100%"  rows="5" placeholder="简要记录一下做了什么，以及需要提醒伙伴注意的情况">{$strDuty['content']}</textarea>
							</div>
							<!--<div  name="job" id="tseditor" rows="5" placeholder="简要记录一下做了什么，以及需要提醒伙伴注意的情况">-->
						</div>
					</div>



					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">

							<button data-id="submit" type="submit" class="btn btn-success">点击提交</button>
						</div>
					</div>
				</form>

			</div>



</div>
		</div>
	</div>


<div class="col-md-4">

    <!--广告位-->
    {php doAction('gobad','300')}
</div>


</div>
</div>


<div id="do_group_form" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" >
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h5 class="modal-title">选择服务处所</h5>
			</div>
			<div class="modal-body" >
				<form  id="set_group" class="form-horizontal"  method="post" action="">


					<div class="form-group">
						<div class="col-sm-12">
							<select  name="groupid" id="groupid" class="form-control">
								<option></option>
								{loop $strGroup $key $item}
								<option value="{$item['groupid']}" {if $item['groupid']==$strDuty['groupid']}selected{/if}>{$item['groupname']}</option>
								{/loop}
							</select>
						</div>
					</div>
					<div class="form-group">
						<div class="col-sm-offset-2 col-sm-10">
							<button type="submit" class="btn btn-success">提交</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>



<script>
	$('#record').on('submit', function(e) {
		var dutyid  = $('#dutyid').val();
		var idcard = $.trim($('#idcard').val());
		var username = $('#username').val();
		var groupid  = $('#gid').val();
		var cateid  = $('#cateid').val();
		var begintime  = $('#beginTime').val();
		var endtime  = $('#endTime').val();
		var period  = $('#period').val();
		var commute  = $('#commute').val();
		var job  = $('content').val();

		if (cateid == '') {
			bootbox.alert('服务类型不能为空');
			return false;
		}

		if (groupid == '') {
			bootbox.alert('服务处所不能为空');
			return false;
		}
		if (cateid == '1' && groupid=='1') {
			bootbox.alert('服务类型与服务处所不匹配');
			return false;
		}


		if(username == ''){
			bootbox.alert('姓名不能为空');
			return false;
		}


		 $.ajax({
		 url: "{SITE_URL}index.php?app=user&ac=do&ts=add",
		 type: 'POST',
		 dataType: 'json',
		 data: {dutyid:dutyid,idcard:idcard,groupid:groupid,cateid:cateid,begintime:begintime,endtime:endtime,period:period,commute:commute,job:job,username:username},
		 success :function(result) {
			 if(result == '1'){
				 window.location.reload();
			  }
		 }
		 });

	});




	//隐藏列表，显示登记表单
	function openEditor(){
		$('#dutyshow').hide();
		$('#do_duty_form').show();
	}

	function closeEditor(){
		$('#dutyshow').show();
		$('#do_duty_form').hide();
	}

	$('#begintime').datetimepicker({
		language:  'zh-CN',
		autoclose: true,
		format: 'yyyy-mm-dd hh:ii'
	});

	$('#endtime').datetimepicker({
		language:  'zh-CN',
		autoclose: true,
		format: 'yyyy-mm-dd hh:ii'
	});

	//筛选分馆
	function jumpto(url,groupid){

       window.location.href=url+'&groupid='+groupid;
	}

	//统计截止时间表单
	function doDateForm(){

			var content = $("#do_date_form").html();
			tsNotice(content);
	}

	//登记服务填写表单
	function doDutyForm(userid){

		if(userid==0){
			tsNotice('请登录后再操作！');
		}else{

			var content = $("#do_duty_form").html();
			tsNotice(content);
		}
	}
	//删除服务记录
	function delDuty(dutyid){


		if (confirm('删除这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=del",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){

					window.location.reload();

				}
			});

		}
	}
	//核定服务记录
	function verify(dutyid){


		if (confirm('核定这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=verify",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){

						window.location.reload();
				}
			});

		}
	}

	//取消核定
	function cancel(dutyid){

		if (confirm('取消核定这条服务记录吗？')) {

			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=user&ac=do&ts=cancel",
				data: "dutyid="+dutyid,
				beforeSend:function(){
				},
				success:function(result){
					if(result == '1'){
						window.location.reload();
					}
				}
			});
		}
	}


	$(function(){
		$('#set_group').on('submit', function(e) {
			var groupid  = $('#groupid').val();
			var dutyid = {php echo $dutyid };
			$.ajax({
				type: "POST",
				url: siteUrl+"index.php?app=duty&ac=setgroup",
				data: "dutyid="+dutyid+"&groupid="+groupid,
				beforeSend:function(){
				},
				success:function(result){
					if(result['status'] == 1){
						window.location.reload();
					}
				}
			});

		});

	});


</script>

{if $edit==1}
<script>
	$('#dutyshow').hide();
	$('#do_duty_form').show();
</script>
{/if}
{php doAction('tseditor','m')}
{template footer}